/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Server.ImplementInterface;

import Interface.IRemoteSavingType;
import Server.DTO.SavingType_DTO;
import java.rmi.RemoteException;
import static java.rmi.server.RemoteServer.getClientHost;
import java.rmi.server.ServerNotActiveException;
import java.rmi.server.UnicastRemoteObject;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author 10520_000
 */
public class SavingTypeObject extends UnicastRemoteObject implements IRemoteSavingType{

    public SavingTypeObject() throws RemoteException{
        super();
    }
    @Override
    public int Insert(SavingType_DTO info) throws RemoteException {
        try {
            System.out.println("Invoke Insert from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        return SavingTypeRepository.Insert(info);
    }

    @Override
    public int Update(SavingType_DTO info) throws RemoteException {
        int result = -1;
        try {
            System.out.println("Invoke Update from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        try {
            result = SavingTypeRepository.Update(info);
        } catch (SQLException ex) {
            Logger.getLogger(SavingTypeObject.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }

    @Override
    public int Delete(SavingType_DTO info) throws RemoteException {
        try {
            System.out.println("Invoke Delete from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        return SavingTypeRepository.Delete(info);
    }

    @Override
    public ArrayList FindAll() throws RemoteException {
        return SavingTypeRepository.FindAll();
    }

    @Override
    public SavingType_DTO FindByTypeID(String TypeID) throws RemoteException {
        try {
            System.out.println("Invoke Find By TypeID from " + getClientHost());
        } catch (ServerNotActiveException snae) {
            snae.printStackTrace();
        }
        return SavingTypeRepository.FindByTypeID(TypeID);
    }

    @Override
    public String GetSavingType(String str_TypeName, int str_Term) throws RemoteException {
        String result="";
        try {
            result=SavingTypeRepository.GetSavingType(str_TypeName, str_Term);
            
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        } catch (SQLException ex) {
            Logger.getLogger(SavingTypeObject.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }

    @Override
    public ArrayList GetNames() throws RemoteException {
        ArrayList arr = null;
        try {
            arr = SavingTypeRepository.GetNames();
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        } catch (SQLException ex) {
            Logger.getLogger(SavingTypeObject.class.getName()).log(Level.SEVERE, null, ex);
        }
        return arr;
    }
    
    @Override
    public boolean Check_TypeID_Exist(String str_TypeID) throws RemoteException {
        boolean result = false;
        try {
            result = SavingTypeRepository.Check_TypeID_Exists(str_TypeID);
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        } catch (SQLException ex) {
            Logger.getLogger(SavingTypeObject.class.getName()).log(Level.SEVERE, null, ex);
        }
        return result;
    }
    
    @Override
    public ArrayList GetSavingTypes(String str_TypeName) throws RemoteException {
        ArrayList ar=null;
        try {
            ar=SavingTypeRepository.GetSavingTypes(str_TypeName);
            //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        } catch (SQLException ex) {
            Logger.getLogger(SavingTypeObject.class.getName()).log(Level.SEVERE, null, ex);
        }
        return ar;
    }
    
    public static void main(String[] str) throws RemoteException
    {
        SavingTypeObject obj = new SavingTypeObject();
        ArrayList arr = obj.GetTerms();
        for(int i=0;i<arr.size();i++)
        {
            System.out.println(arr.get(i));
        }
    }

    @Override
    public ArrayList GetTerms() throws RemoteException {
        ArrayList arr = null;
        try {
            arr = SavingTypeRepository.GetTerms();
        } catch (SQLException ex) {
            Logger.getLogger(SavingTypeObject.class.getName()).log(Level.SEVERE, null, ex);
        }
        return arr;
        
    }

    

    
}
